package com.gua.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.gua.common.response.AjaxResult;
import com.gua.encrypt.annotation.Decryption;
import com.gua.encrypt.annotation.Encryption;
import com.gua.encrypt.dto.AjaxResultBuilder;

/**
 * @author huangjj
 * @description: 测试Controller
 */
@RestController
public class TestController implements AjaxResultBuilder {

	/**
	 * 直接返回对象，不加密
	 * 
	 * @param teacher Teacher对象
	 * @return 不加密的对象
	 */
	@PostMapping("/open/get")
	public ResponseEntity<AjaxResult<?>> get(@Validated @RequestBody Teacher teacher) {
		return success(teacher);
	}

	/**
	 * 返回加密后的数据
	 * 
	 * @param teacher Teacher对象
	 * @return 返回加密后的数据 ResponseBody<Result>格式
	 */
	@PostMapping("/open/encrypt")
	@Encryption
	public ResponseEntity<AjaxResult<?>> encrypt(@Validated @RequestBody Teacher teacher) {
		return success(teacher);
	}

	/**
	 * 返回加密后的数据
	 * 
	 * @param teacher Teacher对象
	 * @return 返回加密后的数据 Result格式
	 */
	@PostMapping("/open/encrypt1")
	@Encryption
	public AjaxResult<?> encrypt1(@Validated @RequestBody Teacher teacher) {
		return success(teacher).getBody();
	}

	/**
	 * 返回解密后的数据
	 * 
	 * @param teacher Teacher对象
	 * @return 返回解密后的数据
	 */
	@PostMapping("/open/decrypt")
	@Decryption
	public ResponseEntity<AjaxResult<?>> decrypt(@Validated @RequestBody Teacher teacher) {
		return success(teacher);
	}

	/**
	 * 返回解密后的数据
	 * 
	 * @param teacher Teacher对象
	 * @return 返回解密后的数据
	 */
	@PostMapping("/open/decrypt2")
	@Decryption
	@Encryption
	public ResponseEntity<AjaxResult<?>> decrypt2(@Validated @RequestBody Teacher teacher) {
		return success(teacher);
	}

}
